package com.example.asepect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogAspect {
    @Before("execution(* com.example.service.MyService.work(..))")
    public void before(){
        System.out.println("log before....");
    }
    @After("execution(* com.example.service.MyService.work(..))")
    public void after(){
        System.out.println("log after....");
    }
    @Around("execution(* com.example.service.MyService.work(..))")
    public Object around(ProceedingJoinPoint point){
        Object rs=null;
        System.out.println("log before in around....");
        try {
            rs = point.proceed(point.getArgs());
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("log after in around....");
        return rs;
    }
}
